package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.MovementMqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;
    @Autowired
    private MovementMqService movementMqService;


    @GetMapping(name="分页查询指定动态收到的评论")
    public ResponseEntity queryComments(String movementId,
                                        @RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10")Integer pagesize){

        return commentsService.queryComments(movementId,page,pagesize);
    }

    @PostMapping(name="发布评论")
//    {"movementId":"3refsfdsfvvsvds","comment":"你好美~约吗？"}
    public ResponseEntity saveComments(@RequestBody Map map){
        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");
        movementMqService.sendMsgToMq(movementId,4);
        return commentsService.saveComments(movementId,comment);
    }
}
